import java.util.Deque;
import java.util.LinkedList;

public class Solution150 {
    public int evalRPN(String[] tokens) {
        Deque<Integer> nums = new LinkedList<>();
        for (String token : tokens) {
            try {
                int num = Integer.parseInt(token);
                nums.push(num);
            } catch (Exception e) {
                int b = nums.pop();
                int a = nums.pop();
                switch (token.charAt(0)) {
                    case '+':
                        nums.push(a + b);
                        break;
                    case '-':
                        nums.push(a - b);
                        break;
                    case '*':
                        nums.push(a * b);
                        break;
                    case '/':
                        nums.push(a / b);
                }
            }
        }
        return nums.pop();
    }

}
